# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libnice
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.1.17
pkgrel=1
pkgdesc="An implementation of the IETF's draft ICE (for p2p UDP data streams) (mingw-w64)"
arch=('any')
url="https://nice.freedesktop.org/wiki/"
license=("LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-gstreamer"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "${MINGW_PACKAGE_PREFIX}-gtk-doc"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja")
depends=("${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-gnutls"
         #"${MINGW_PACKAGE_PREFIX}-openssl"
        )
optdepends=("${MINGW_PACKAGE_PREFIX}-gstreamer")
options=('staticlibs' 'strip')
source=("https://nice.freedesktop.org/releases/${_realname}-${pkgver}.tar.gz")
sha256sums=('1952a0dec58b5c9ccc3f25193df4e2d1244cb382cac611b71e25afcd7b069526')

prepare() {
  cd ${_realname}-${pkgver}
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}"

  ${MINGW_PREFIX}/bin/meson \
    --buildtype=plain \
    -Dintrospection=enabled \
    -Dgtk_doc=enabled \
    -Dcrypto-library=gnutls \
    "../${_realname}-${pkgver}"

  ${MINGW_PREFIX}/bin/ninja
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  DESTDIR="${pkgdir}${MINGW_PREFIX}" ninja install

  local _PRE_WIN="$(cygpath -m ${MINGW_PREFIX})"
  sed -e "s|${_PRE_WIN}|${MINGW_PREFIX}|g" \
    -i ${pkgdir}${MINGW_PREFIX}/lib/pkgconfig/nice.pc

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING"      "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING.LGPL" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING.LGPL"
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING.MPL"  "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING.MPL"
}
